package com.qf.smartplatform.event.listener;

import com.qf.smartplatform.event.DeviceStatusEvent;
import com.qf.smartplatform.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/*** @author Tgb
 * @version V1.0
 * @Project smartplatform
 * @Package com.qf.smartplatform.event.listener
 * @Description:
 * @Date 2022/9/13 18:19
 */
@Component
public class DeviceStatusEventListener {
    private DeviceService deviceService;
    @Autowired
    public void setDeviceService(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @EventListener
    public void onEvent(DeviceStatusEvent event){
        deviceService.updateDeviceStatus(event.getDeviceId(),event.getStatus()==DeviceStatusEvent.Status.OFFLINE?0:1);
    }
}
